/*!
 * \file UserContext.h
 * \brief User context keeps all the necessary information about the user
 * client
 */

#ifndef SGW_USER_CONTEXT_H
#define SGW_USER_CONTEXT_H

#include <stdint.h>
#include <map>
#include "common.pb.h"

namespace tsc
{
namespace sgw
{

/**
 * User context keeps all the necessary information about the User Client
 */
class UserContext
{
public:

	/**
	 * Creates user context for user with specified client ID
	 */
	UserContext(uint32_t clientId);

	/**
	 * Destructor
	 */
	~UserContext();

	/**
	 * Returns ID of the User Client
	 * \return id of client
	 */
	uint32_t getUserClientId() const;

	ProtocolsCommon::IpAddress* getClientIpAddress() const;

	void setClientIpAddress(ProtocolsCommon::IpAddress* ip);

	uint32_t getClientUapPort() const;

	void setClientUapPort(uint32_t port);

	static bool findContext(uint32_t clientId, UserContext*& context);

	void generatorCreated();

	void generatorRemoved();

private:
	/**
	 * Id of a User Client that is 24 first bits of the clientId send
	 * within UAP PDUs
	 */
	int mUserClientId;

	/**
	 * IP address of the User Client
	 */
	ProtocolsCommon::IpAddress* mpClientAddress;

	/**
	 * Port for UAP protocol on User Client's side
	 */
	uint32_t mClientUapPort;

	/**
	 * Number of UapGenerators connected with this context
	 */
	size_t mNumOfGenerators;

	/**
	 * Map holding UserContexts, key is the 24-bit user client id
	 */
	static std::map<uint32_t, UserContext*> msContextMap;
};

} // namespace sgw
} // namespace tsc

#endif // SGW_UAP_GENERATOR_H
